part of 'api.dart';

// ignore: library_private_types_in_public_api
extension ApiActivity on _Api {
  Future<MerchatPicture?> getActivityImages(int type) async {
    try {
      final resp = await httpInstance.get(
          url: 'info/activity/images',
          queryMap: {
            'type': type,
          },
          complete: MerchatPicture.fromJson);

      return resp;
    } catch (e) {
      return null;
    }
  }

  Future<List<ActivityUserModel>?> getUserByActivityId({
    required int activityId,
  }) async {
    try {
      final resp = await httpInstance.get(
        url: 'info/activity/user',
        queryMap: {
          'activityId': activityId,
        },
        complete: ActivityUserModel.fromJson,
      );
      return resp ?? [];
    } catch (e) {
      return null;
    }
  }

  Future<List<SuperActivityModel>?> getActivityItems({
    required int page,
    required int pageSize,
  }) async {
    try {
      final resp = await httpInstance.get(
        url: 'info/activity/list',
        queryMap: {
          'page': page,
          'pageSize': pageSize,
        },
        complete: SuperActivityModel.fromJson,
      );
      return resp ?? [];
    } catch (e) {
      return null;
    }
  }

  Future<List<SuperActivityModel>?> getMyParticipated({
    required int page,
    required int pageSize,
  }) async {
    try {
      final resp = await httpInstance.get(
        url: 'info/activity/myParticipated',
        queryMap: {
          'page': page,
          'pageSize': pageSize,
        },
        complete: SuperActivityModel.fromJson,
      );
      return resp ?? [];
    } catch (e) {
      return null;
    }
  }

  Future<ActivityDetailModel?> getDetailByActivityId({
    required int activityId,
  }) async {
    try {
      final resp = await httpInstance.get(
        url: 'info/activity/detail',
        queryMap: {
          'activityId': activityId,
        },
        complete: ActivityDetailModel.fromJson,
      );
      return resp;
    } catch (e) {
      return null;
    }
  }

  Future<bool?> joinByActivityId(int activityId) async {
    try {
      await httpInstance.post(
        url: 'info/activity/join',
        body: {'activityId': activityId},
      );
      return true;
    } catch (e) {
      return null;
    }
  }
}
